package com.shop2cn.iapi.wxcomponent.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.wxcomponent.parameter.NofifyChargeStatusBean;
import com.shop2cn.iapi.wxcomponent.service.NofifyChargeStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.mapping.wxcomponent.MchappSqlProvider;
import com.ymttest.database.mapping.wxcomponent.MchchargerecordSqlProvider;
import com.ymttest.database.model.MchchargerecordExample;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*收费单状态变更Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_NofifyChargeStatus{
	private static NofifyChargeStatusBean nofifychargestatusBean;
	private static NofifyChargeStatusCall nofifychargestatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("收费单状态变更Test");
	}

	@Before
	public void caseUp() {
		nofifychargestatusBean=new NofifyChargeStatusBean();
		nofifychargestatusCall=new NofifyChargeStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(nofifychargestatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NofifyChargeStatus_001() {
		Logger.start(true,"成功进行付费，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
           //申请付费 
            WxComponentService.ApplyCharge(mchid);
            //查询付费单号
            String tradingId = new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getMchChargeRecordId();
            Logger.verifyEquals(0, new DefGodMchWapper().selectMchappByExample(mchid).get(0).getChargeStatus(), "还未付费");
            nofifychargestatusBean.setTradingId(tradingId);
            nofifychargestatusBean.setPayTime("20191225144331");
            nofifychargestatusBean.setPaymentId("20191225144331");
            
            nofifychargestatusCall.setData(nofifychargestatusBean);
			nofifychargestatusCall.callService();			
			Logger.verifyEquals("200", nofifychargestatusCall.getString("code"), "验证code");
			Logger.verifyEquals(1, new DefGodMchWapper().selectMchappByExample(mchid).get(0).getChargeStatus(), "已经付费");
			Logger.verifyEquals(1, new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getChargeStatus(),"付费后，查询订单状态");
//			System.out.println(new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NofifyChargeStatus_002() {
		Logger.start(true,"未申请付费---数据库中应无单号、，失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
           //申请付费 
//            WxComponentService.ApplyCharge(mchid);
            try {
            	 //查询付费单号
            	String tradingId = new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getMchChargeRecordId();
            	  nofifychargestatusBean.setTradingId(tradingId);
                  nofifychargestatusBean.setPayTime("20191225144331");
                  nofifychargestatusBean.setPaymentId("20191225144331");
                  
                  nofifychargestatusCall.setData(nofifychargestatusBean);
      			nofifychargestatusCall.callService();			
      			Logger.verifyEquals("200", nofifychargestatusCall.getString("code"), "验证code");
            	Logger.verifyEquals("1", "2", "错误");
			} catch (Exception e) {
				Logger.verifyEquals("1", "1", "测试");
				Logger.verifyEquals(0, new DefGodMchWapper().selectMchappByExample(mchid).get(0).getChargeStatus(), "还未付费");
			}
          
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NofifyChargeStatus_003() {
		Logger.start(true,"订单号错误，失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
           //申请付费 
            WxComponentService.ApplyCharge(mchid);
            //查询付费单号
            String tradingId = new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getMchChargeRecordId();
            
            nofifychargestatusBean.setTradingId(tradingId+"123123");
            nofifychargestatusBean.setPayTime("20191225144331");
            nofifychargestatusBean.setPaymentId("20191225144331");
            
            nofifychargestatusCall.setData(nofifychargestatusBean);
			nofifychargestatusCall.callService();			
			Logger.verifyEquals("400", nofifychargestatusCall.getString("code"), "验证code");
			Logger.verifyEquals(0, new DefGodMchWapper().selectMchappByExample(mchid).get(0).getChargeStatus(), "还未付费");
			Logger.verifyEquals(0, new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getChargeStatus(),"还未付费，查询订单状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NofifyChargeStatus_004() {
		Logger.start(true,"时间为空,失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
           //申请付费 
            WxComponentService.ApplyCharge(mchid);
            //查询付费单号
            String tradingId = new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getMchChargeRecordId();
            nofifychargestatusBean.setTradingId(tradingId);
//            nofifychargestatusBean.setPayTime("20191225144331");
            nofifychargestatusBean.setPaymentId("20191225144331");
            
            nofifychargestatusCall.setData(nofifychargestatusBean);
			nofifychargestatusCall.callService();
			Logger.verifyEquals("400", nofifychargestatusCall.getString("code"), "验证code");
			Logger.verifyEquals(0, new DefGodMchWapper().selectMchappByExample(mchid).get(0).getChargeStatus(), "还未付费");
			Logger.verifyEquals(0, new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getChargeStatus(),"还未付费，查询订单状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	
	
}